package org.pay.model;

import android.text.TextUtils;
import android.util.Log;

import org.pay.utils.HashUtils;
import org.pay.utils.StringUtils;

public class BaseModel {

    //9999 已加密之交易請求資料, 採用 openssl / aes-256-cbc對稱式加密
    private String TransactionData;
    //64 校驗碼(採用 sha256 Hash 作為驗證比對計算使用。(若無加密資訊時帶空值)
    private String HashDigest = "";

    boolean hasBody = false;
    boolean hashCheck = false;


    public BaseModel(String transactionData) {
        this.TransactionData = transactionData;
        if (this.HashDigest.isEmpty() && StringUtils.isNotEmpty(transactionData)) {
            this.HashDigest = HashUtils.digestSha256Value(transactionData);
        }
    }

    public BaseModel(String transactionData, String hashDigest) {
        this.TransactionData = transactionData;
        this.HashDigest = hashDigest;
        if (StringUtils.isNotEmpty(transactionData)) {
            hasBody=true;
            String newHash = HashUtils.digestSha256Value(transactionData);
            this.hashCheck = TextUtils.equals(hashDigest, newHash);
        } else {
            this.hashCheck = true;
        }


    }

    public boolean isHashCheck() {
        return this.hashCheck;
    }

    public boolean isHasBody(){
        return hasBody;
    }
    public String getTransactionData() {
        return TransactionData;
    }

    public void setTransactionData(String transactionData) {
        TransactionData = transactionData;
    }

    public String getHashDigest() {
        return HashDigest;
    }

    public void setHashDigest(String hashDigest) {
        HashDigest = hashDigest;
    }

    @Override
    public String toString() {
        return "BasePayJson{" +
                "TransactionData='" + TransactionData + '\'' +
                ", HashDigest='" + HashDigest + '\'' +
                '}';
    }


}
